package com.netease.rtcdemo;

import android.graphics.Rect;
import android.util.Log;

import com.netease.lava.nertc.sdk.LastmileProbeResult;
import com.netease.lava.nertc.sdk.NERtcCallbackEx;
import com.netease.lava.nertc.sdk.NERtcUserJoinExtraInfo;
import com.netease.lava.nertc.sdk.NERtcUserLeaveExtraInfo;
import com.netease.lava.nertc.sdk.audio.NERtcAudioStreamType;
import com.netease.lava.nertc.sdk.stats.NERtcAudioVolumeInfo;
import com.netease.lava.nertc.sdk.video.NERtcVideoCodecType;
import com.netease.lava.nertc.sdk.video.NERtcVideoStreamType;

import java.nio.ByteBuffer;
import java.util.ArrayList;

public class NERtcCallback implements NERtcCallbackEx {
    private static NERtcCallback instance;
    private ArrayList<callbackDelegate> delegateList = new ArrayList<>();

    // 私有构造函数，防止外部直接实例化
    private NERtcCallback() {
        // 进行初始化工作
    }
    public void registerDelegate(callbackDelegate delegate) {

        delegateList.add(delegate);
        Log.d("qweqwe", "registerDelegate :" + delegateList.size());
    }
    public void removeDelegate() {
        delegateList.remove(delegateList.size() - 1);
        Log.d("qweqwe", "removeDelegate  :" + delegateList.size());
    }
    public static NERtcCallback getInstance() {
        if (instance == null) {
            instance = new NERtcCallback();
        }
        return instance;
    }

    @Override
    public void onUserSubStreamVideoStart(long uid, int maxProfile) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onUserSubStreamVideoStart(uid, maxProfile);
        }
    }

    @Override
    public void onUserSubStreamVideoStop(long uid) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onUserSubStreamVideoStop(uid);
        }
    }

    @Override
    public void onUserAudioMute(long uid, boolean muted) {

    }

    @Override
    public void onUserVideoMute(long uid, boolean muted) {

    }

    @Override
    public void onUserVideoMute(NERtcVideoStreamType streamType, long uid, boolean muted) {

    }

    @Override
    public void onFirstAudioDataReceived(long uid) {

    }

    @Override
    public void onLocalAudioFirstPacketSent(NERtcAudioStreamType audioStreamType) {

    }

    @Override
    public void onFirstVideoDataReceived(long uid) {

    }

    @Override
    public void onFirstVideoDataReceived(NERtcVideoStreamType streamType, long uid) {

    }

    @Override
    public void onFirstAudioFrameDecoded(long userID) {

    }

    @Override
    public void onFirstVideoFrameDecoded(long userID, int width, int height) {

    }

    @Override
    public void onFirstVideoFrameDecoded(NERtcVideoStreamType streamType, long userID, int width, int height) {

    }

    @Override
    public void onUserVideoProfileUpdate(long uid, int maxProfile) {

    }

    @Override
    public void onAudioDeviceChanged(int selected) {

    }

    @Override
    public void onAudioDeviceStateChange(int deviceType, int deviceState) {

    }

    @Override
    public void onVideoDeviceStageChange(int deviceState) {

    }

    @Override
    public void onLocalVideoEncoderDidOccurError(NERtcVideoStreamType neRtcVideoStreamType, NERtcVideoCodecType neRtcVideoCodecType, boolean b, int i) {

    }

    @Override
    public void onConnectionTypeChanged(int newConnectionType) {

    }

    @Override
    public void onReconnectingStart() {

    }

    @Override
    public void onReJoinChannel(int result, long channelId) {

    }

    @Override
    public void onAudioMixingStateChanged(int reason) {

    }

    @Override
    public void onAudioMixingTimestampUpdate(long timestampMs) {

    }

    @Override
    public void onAudioEffectTimestampUpdate(long id, long timestampMs) {

    }

    @Override
    public void onAudioEffectFinished(int effectId) {

    }

    @Override
    public void onLocalAudioVolumeIndication(int volume) {

    }

    @Override
    public void onLocalAudioVolumeIndication(int volume, boolean vadFlag) {

    }

    @Override
    public void onRemoteAudioVolumeIndication(NERtcAudioVolumeInfo[] volumeArray, int totalVolume) {

    }

    @Override
    public void onLiveStreamState(String taskId, String pushUrl, int liveState) {

    }

    @Override
    public void onConnectionStateChanged(int state, int reason) {

    }

    @Override
    public void onCameraFocusChanged(Rect rect) {

    }

    @Override
    public void onCameraExposureChanged(Rect rect) {

    }

    @Override
    public void onRecvSEIMsg(long userID, String seiMsg) {

    }

    @Override
    public void onAudioRecording(int code, String filePath) {

    }

    @Override
    public void onError(int code) {

    }

    @Override
    public void onWarning(int code) {

    }

    @Override
    public void onMediaRelayStatesChange(int state, String channelName) {

    }

    @Override
    public void onMediaRelayReceiveEvent(int event, int code, String channelName) {

    }


    @Override
    public void onLocalPublishFallbackToAudioOnly(boolean isFallback, NERtcVideoStreamType streamType) {

    }

    @Override
    public void onRemoteSubscribeFallbackToAudioOnly(long uid, boolean isFallback, NERtcVideoStreamType streamType) {

    }

    @Override
    public void onLastmileQuality(int quality) {

    }

    @Override
    public void onLastmileProbeResult(LastmileProbeResult result) {

    }

    @Override
    public void onMediaRightChange(boolean isAudioBannedByServer, boolean isVideoBannedByServer) {

    }

    @Override
    public void onVirtualBackgroundSourceEnabled(boolean enabled, int reason) {

    }

    @Override
    public void onUserSubStreamAudioStart(long uid) {

    }

    @Override
    public void onUserSubStreamAudioStop(long uid) {

    }

    @Override
    public void onUserSubStreamAudioMute(long uid, boolean muted) {

    }

    @Override
    public void onPermissionKeyWillExpire() {

    }

    @Override
    public void onUpdatePermissionKey(String key, int error, int timeout) {

    }

    @Override
    public void onLocalVideoWatermarkState(NERtcVideoStreamType videoStreamType, int state) {

    }

    @Override
    public void onJoinChannel(int result, long channelId, long elapsed, long uid) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onJoinChannel(result,channelId,elapsed,uid);
        }
    }

    @Override
    public void onLeaveChannel(int result) {

    }

    @Override
    public void onUserJoined(long uid) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onUserJoined(uid);
        }
    }

    @Override
    public void onUserJoined(long uid, NERtcUserJoinExtraInfo joinExtraInfo) {

    }

    @Override
    public void onUserLeave(long uid, int reason) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onUserLeave(uid, reason);
        }
    }

    @Override
    public void onUserLeave(long uid, int reason, NERtcUserLeaveExtraInfo leaveExtraInfo) {

    }

    @Override
    public void onUserAudioStart(long uid) {

    }

    @Override
    public void onUserAudioStop(long uid) {

    }

    @Override
    public void onUserVideoStart(long uid, int maxProfile) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onUserVideoStart(uid, maxProfile);
        }
    }

    @Override
    public void onUserVideoStop(long uid) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onUserVideoStop(uid);
        }
    }

    @Override
    public void onDisconnect(int reason) {
        for(int i = 0;i < delegateList.size() ;i++){
            delegateList.get(i).onDisconnect(reason);
        }
    }

    @Override
    public void onClientRoleChange(int oldRole, int newRole) {

    }
}
